from ttzScrapyProject.items import LotterInfoItem
from ttzScrapyProject.utils import DateUtils
from ttzScrapyProject.utils import StrigUtils
from ttzScrapyProject.utils import MumberUtils


def parseLotteryInfo(self, data):
    lotteryInfoList = []

    for item in data:
        loItem = LotterInfoItem()
        loItem["lotteryId"] = item["Id"]
        loItem["lotteryLuckNum1"] = item["Num1"]
        loItem["lotteryLuckNum2"] = item["Num2"]
        loItem["lotteryLuckNum3"] = item["Num3"]
        loItem["lotteryLuckNum"] = item["LuckNum"]
        loItem["luckNumRate"] = item["LuckNumRate"]
        loItem["lottery_open_time"] = DateUtils.timestamp2Date(int(item["LotteryTime"]))
        loItem["totalSum"] = item["TotalSum"]
        loItem["lottery_transfer_time"] = DateUtils.getDate()
        loItem["transferAmount"] = 0
        loItem["isTransfer"] = "否"

        totalSum = item["TotalSum"]
        luckNumRate = item["LuckNumRate"]
        teim = DateUtils.timestamp2Date(int(item["UpdateTime"]))
        luckNumString = StrigUtils.convertNumString(loItem["lotteryLuckNum"])
        if luckNumString in item:
            luckNumSum = item[luckNumString]
            totalSumTemp = int(luckNumSum) * float(luckNumRate)
            booleanCompare = MumberUtils.compare(totalSumTemp, float(totalSum))
            # print(
            #     f"时间为{teim},当前号码的下注额{luckNumSum},当前号码赔率{luckNumRate},中奖后的奖池为{totalSumTemp},当前的奖池为{totalSum},当前号码的中奖额与总奖池相比{booleanCompare}")
        lotteryInfoList.append(loItem)

    # print(lotteryInfoList)
    return lotteryInfoList


"""
    获取即将开奖的号码押注信息
"""


def parseDoingLotteryInfoItem(self, data):
    lotteryInfoMap = {}
    doingData = data[-1]
    numMap = StrigUtils.initNumMap()
    for val in numMap.values():
        lotteryInfoMap[val] = doingData[val]
    return lotteryInfoMap
